package brinaryTree;

import java.util.ArrayDeque;
import java.util.Deque;

public class N104_MaxDepth {
    public int maxDepth(TreeNode root) {
        Deque<TreeNode> deque = new ArrayDeque<>();
        int depth = 0;
        if (root != null) deque.add(root);
        while (!deque.isEmpty()) {
            depth++;
            int size = deque.size();
            for (int i = 0; i < size; i++) {
                TreeNode node = deque.pop();
                if (node.left != null) deque.add(node.left);
                if (node.right != null) deque.add(node.right);
            }
        }
        return depth;
    }
}
